/*
 * 游戏类型列表
 * */
import React from 'react'
import { connect } from 'dva'
import { Form,Modal } from 'antd'
import { Link, hashHistory } from 'dva/router'
import FlagBtn from 'widget/FlagBtn/FlagView'
import config from 'config/config'
import { mapStateToProps } from 'utils/view_utils'
import styles from './gameStatusListStyle.less'
import ListPage from 'widget/PageTmpl/ListPage'
import { Button } from 'antd/lib/radio';
const confirm = Modal.confirm;
// let subElements = JSON.parse(localStorage.getItem('navBar')).subElements
const gameStatusListView = function ({ dispatch, model, form }) {
  
    const { resetFields, getFieldDecorator, validateFields, setFieldsValue } = form
    const { modelObj, namespace } = model
    let { } = modelObj
      // 分页表格属性配置
  let pageProps = {
    // ---------- 界面部分 ----------
    'ui': {
      // 页面接口地址
      'api_url': 'mideadc-game-center-service/activity/gameActivityType/list',
      // "api_url": "admin/housetype/list",
      // 接口方式
      'data_field_name':'result.records',
      'data_pageNo':'result.current',
      'data_pageSize':'result.size',
      'data_total':'result.total',
      'method': 'GET',
      'app': 'isales-mgmt-application',
      // 接口参数
      'params': '',
      // 模拟数据 - 用于开发需要，若填充了上面的api_url之后，请将此项设置为null
      // "mockData": mockData,
      'mockData': null,
      // 数据表格
      'table': {
        'status_params': 'status=0',
        'status_text': '全部',
        'scroll': { x: 1000 },
        'action_props': { width: 200 },
        // 表头字段列表"
        'fields': [
          // {
          //   en_name: "key",
          //   zh_name: "序号",
          //   width: 60,
          //   render: (a, item, index, d, e, f) => {
          //     return index + 1
          //   },
          // },
          {
            'en_name': 'gameImgUrl',
            'zh_name': '游戏图片',
            width: 200,
            render: (a, item, index, d, e, f) => {
              if(item.gameImgUrl && item.gameImgUrl != ''){
                return <img src={item.gameImgUrl} style={{width:'200px',height:'50px'}}></img>
              }
              return '';
            }
          },
          {
            'en_name': 'gameName',
            'zh_name': '游戏名称',
            width: 200
          },
          {
            'en_name': 'description',
            'zh_name': '游戏描述',
            width: 200
          },
          {
            'en_name': 'availCount',
            'zh_name': '操作',
            width: 200,
            render: (a, item, index, d, e, f) => {
              return (
                <span>
                  <FlagBtn node={<a onClick={() => editGameStatus(item)}>编辑<span className="ant-divider" style={{ display: 'inline-block' }} /></a>} > </FlagBtn>
                  {/* <Popconfirm placement="top" title={"确定删除当前游戏类型吗？"} onConfirm={() => delStatus(item)} okText="确定" cancelText="取消">
                    <FlagBtn node={<a>删除<span className="ant-divider" style={{ display: 'inline-block' }} /></a>} > </FlagBtn>
                  </Popconfirm> */}
                  <FlagBtn node={<a onClick={() => delStatus(item)}>删除<span className="ant-divider" style={{ display: 'inline-block' }} /></a>} > </FlagBtn>
                  {/* <FlagBtn node={<a onClick={() => gotoActivePage(item)}>活动列表<span className="ant-divider" style={{ display: 'inline-block' }} /></a>} > </FlagBtn> */}
                </span>
              ) 
            },
          },
        ],
      },
      // 操作栏
      action_bar: [
        {
          'func_name': 'add',
          'label': '新建类型',
          // btnId: '20501',
          'type': 'primary',
          'onClick': (e) => {
            hashHistory.push({
              pathname: "/home/advertisementAdmin/gameStatusEdit", 
              query: { ststusId: ''}
            }) 
          }
        },
      ],
    },
  }
  if (!!modelObj.biz) {
    pageProps.biz = modelObj.biz
    pageProps.biz.syncBackCbf = (biz) => {
      dispatch({
        type: `${namespace}/updateStore`,
        payload: { biz }
      })
    }
  }

  //编辑游戏类型
  function editGameStatus(item){
    hashHistory.push({
      pathname: "/home/advertisementAdmin/gameStatusEdit", 
      query: { ststusId: item.id}
    }) 
  }

  //新增游戏规则
  function gotoActivePage(item){
    hashHistory.push({
      pathname: "/home/advertisementAdmin/gameConfigList", 
      query: { gameActivityTypeId: item.id}
    })   
  } 

  function delStatus(item){
    confirm({
      title: '删除确认',
      content: '您真的要删除此游戏类型信息吗?',
      okText: '确认',
      okType: 'primary',
      cancelText: '取消',
      onOk() {
          // debugger
        dispatch({
          type: `${namespace}/delGameStatus`,
          payload: { id:item.id }
        })
      },
      onCancel() {
        console.log('Cancel');
      },
    });
  }
    return (
        <div>
            <ListPage pageProps={pageProps} />
        </div>
    )
}
export default connect(mapStateToProps)(Form.create()(gameStatusListView))
